home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------------------
-
- Program: CPlusTESample 2.0
- File: List.h
-
- by Andrew Shebanow
- of Apple Macintosh Developer Technical Support
-
- Copyright © 1989-1990 Apple Computer, Inc.
- All rights reserved.
-
- ------------------------------------------------------------------------------------------*/
-
- #ifndef __LIST__
- #define __LIST__
-
- // HandleObjectHandle is an Handle full of HandleObject*,
- // which we use as an array
- // We do two typedefs here to make that a
- // bit easier to read, since:
- // typedef HandleObject*** HandleObjectHandle;
- // is just too wierd.
- typedef HandleObject* HandleObjectRef;
- typedef HandleObjectRef** HandleObjectHandle;
-
- class TList : public HandleObject {
- public:
- TList();
-
- virtual void InsertFirst(HandleObject* obj);
- virtual void InsertLast(HandleObject* obj);
-
- virtual void MoveToFront(HandleObject* obj);
- virtual void MoveToBack(HandleObject* obj);
- virtual void MoveFront(HandleObject* obj);
- virtual void MoveBack(HandleObject* obj);
-
- virtual void Remove(HandleObject* obj);
- virtual void RemoveAll();
- virtual void Delete(HandleObject* obj);
- virtual void DeleteAll();
-
- virtual short Count() const;
-
- protected:
- virtual HandleObject* At(short idx) const;
- virtual short FindIdx(HandleObject* obj);
-
- short fNumObjs; // the number of elements in the list
-
- private:
- friend class TListIterator;
-
- HandleObjectHandle fObjects;
- };
-
- // Our inline methods - we do these so often, and they are so small,
- // that we make them inlines
-
- inline short TList::Count() const
- {
- return fNumObjs;
- }
-
- class TListIterator : public HandleObject {
- public:
- TListIterator(const TList* ls);
- virtual HandleObject* Next();
- virtual HandleObject* Prev();
- virtual HandleObject* First();
- virtual HandleObject* Last();
-
- private:
- const TList* fList;
- short fIdx;
- };
-
- inline HandleObject* TListIterator::Next()
- {
- return fList->At(++fIdx);
- }
-
- inline HandleObject* TListIterator::Prev()
- {
- return fList->At(--fIdx);
- }
-
- inline HandleObject* TListIterator::First()
- {
- fIdx = 0;
- return fList->At(fIdx);
- }
-
- inline HandleObject* TListIterator::Last()
- {
- fIdx = fList->Count() - 1;
- return fList->At(fIdx);
- }
-
- #endif
-